/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package week0401;

import java.util.*;

public class Main1 {

    private static Scanner in;

    public static void main(String[] args) {
        in = new Scanner(System.in);
        int n;

        while (true) {
            n = in.nextInt();
            PersonSortable[] personSortables = new PersonSortable[n];
            for (int i = 0; i < n; i++) {
                personSortables[i] = new PersonSortable(in.next(), in.nextInt());
            }
            Arrays.sort(personSortables);
            for (PersonSortable personSortable : personSortables) {
                System.out.println(personSortable.toString());
            }
            System.out.println(Arrays.toString(PersonSortable.class.getInterfaces()));

        }

    }

}

class PersonSortable implements Comparable<PersonSortable> {

    private String name;
    private int age;

    public PersonSortable(String name, int age) {
        super();
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return name + "-" + age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public int compareTo(PersonSortable o) {
        return this.toString().compareTo(o.toString());
    }

}